<?php
 require "./config/mysql.php";
 class userList extends mysqlPdo
 {

  public static function userinfo()

   {
		$pdo = mysqlPdo::getPdoConnect();

		$tr = $pdo -> query("select * from user");
		$str = $tr -> fetchAll(PDO::FETCH_ASSOC);
		$total =$tr -> rowCount();   //获取总记录数;
		$num = 2;             //每页显示的记录数;
		$url = "index.php";          //请求的URL 
		$cpage = isset($_GET["page"])?$_GET["page"]:1;//当前页  
		$pagenum = ceil($total/$num);//总页数 
		$offset = ($cpage-1)*$num;//开始去数据的位置  
		$sql1 = "select * from user limit {$offset},{$num}";
		$tr1 = $pdo -> query($sql1);
		$str1 = $tr1 -> fetchAll(PDO::FETCH_ASSOC);
		$start = $offset+1;//开始记录页 
		$end = ($cpage==$pagenum) ? $total : ($cpage*$num);//结束记录页 
		$next = ($cpage==$pagenum) ? $pagenum : ($cpage+1);//下一页  
		$prev = ($cpage==1) ? 1 : ($cpage-1);//前一页 
    $arr = array(
        'total'=>$total,
        'num'=>$num,
        'url'=>$url,
        'cpage'=>$cpage,
        'pagenum'=>$pagenum,
        'offset'=>$offset,
        'str1'=>$str1,
        'start'=>$start,
        'end'=>$end,
        'next'=>$next,
        'prev'=>$prev,
        );
        return $arr;
   }

   public static function  useredit($username,$email,$id,$password,$phone,$regtime)

   {
        $pdo = mysqlPdo::getPdoConnect();
        $tr  = $pdo -> exec("update user set username = '$username',email = '$email',password = '$password',phone = '$phone',regtime = '$regtime' where id = $id");       
        return $tr;

   }



    public static function  showuser($pid)

   {
        $pdo = mysqlPdo::getPdoConnect();
        $tr1 = $pdo -> query("select * from user where id = $pid");  //显示原来信息
        $str = $tr1 -> fetchAll(PDO::FETCH_ASSOC);    
        return $str;

   }


    public static function deleuser($id)

    {
       $pdo = mysqlPdo::getPdoConnect();
       $tr = $pdo -> exec("delete from user where id= '$id'");
       return $tr;
    }



 }



?>